package com.gitee.linmt.config;

import com.gitee.linmt.cache.DictionaryEnumCache;
import com.gitee.linmt.init.InitDictionaryEnums;
import com.gitee.linmt.properties.ConfigProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lin-mt
 * @version 1.0.0
 * @since 1.0.0
 */
@Configuration
@EnableConfigurationProperties({ConfigProperties.class})
public class DictionaryEnumConfig {

    private final ConfigProperties configProperties;

    public DictionaryEnumConfig(ConfigProperties configProperties) {
        this.configProperties = configProperties;
    }

    @Bean
    @ConditionalOnMissingBean(InitDictionaryEnums.class)
    public InitDictionaryEnums initDictionaryEnums() {
        return new InitDictionaryEnums();
    }

    @Bean
    @ConditionalOnMissingBean(DictionaryEnumCache.class)
    public DictionaryEnumCache dictionaryEnumIntegerCache() {
        return new DictionaryEnumCache(this.configProperties);
    }

}